package com.ericom.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

@Entity
@Table(name="order_item")
public class OrderItem extends BaseObject {
	@ManyToOne(cascade = { CascadeType.MERGE })  
	@JoinColumn(name = "order_id")	
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this).append("id", id)
				.append("product", product).append("price", price)
				.append("quntity", quntity).toString();
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof OrderItem))
			return false;
		OrderItem castOther = (OrderItem) other;
		return new EqualsBuilder().append(id, castOther.id).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).toHashCode();
	}

	@Id@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	@ManyToOne(cascade = { CascadeType.MERGE })  
	@JoinColumn(name = "product_id")	
	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}
@Column(name="f_quantity")
	public float getQuntity() {
		return quntity;
	}

	public void setQuntity(float quntity) {
		this.quntity = quntity;
	}

	private Long id;
	private Product product;
	private float price;
	private float quntity;
	private Order order;
	
	

}
